package com.example.spring_test2.controller;

import com.example.spring_test2.domain.Product;
import com.example.spring_test2.service.productService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/product")
public class productController {

    @Autowired
    productService productservice;

    @PostMapping("/addProduct")
    public void addProduct(@RequestBody Product product){
        productservice.addProduct(product);
    }

    @GetMapping("/getAllProduct")
    public List<Product> getAllProduct(){
        return productservice.getAllProduct();
    }

    @GetMapping("/getProductById")
    public Product getProductById(@PathVariable long id){
        return productservice.getProductById(id);
    }

    @PostMapping("deleteProduct")
    public void deleteProduct(long id){
        productservice.deleteProduct(id);
    }

    @PostMapping("updateProduct")
    public void updateProduct(Product product){
        productservice.updateProduct(product);
    }
}
